/**
 * Popup | 2017 MIT License
 * 官方文档：http://lkx2217.cn
 * 依赖文件：Lkx
 * 模块化前端管理框架 - UI 模块
 * */

(function(win) {

    "use strict";

    //共同获取方法
    //返回基础的document对象
    //基础的querySelector获取方法
    //创建对象的createElement方法
    //兼容当前层以及最顶iframe层
    var native = {
            doc: function(topPage) { return topPage ? win.top.document : document; },
            query: function(dom, topPage) { return native.doc(topPage).querySelector(dom); },
            queryAll: function(dom, topPage) { return native.doc(topPage).querySelectorAll(dom); },
            create: function(dom, topPage) { return native.doc(topPage).createElement(dom); }
        },

        //公共字段
        //记录空字段
        //层级关系和多层偏移量等
        field = {
            empty: /^[ ]*$/,
            zIndex: 199202,
            movesNum: 0,
            remindTimer: null,
            tipsTimer: null,
            offset: ['top', 'right', 'bottom', 'left', 'center']
        },

        //共同使用方法
        //包括判断数据类型是否正常
        //删增class操作
        //显示和隐藏弹窗公共方法
        common = {

            //判断所需字段的数据类型是否符合规范
            str: function(text) { return (typeof text === 'string' && !field.empty.test(text) || typeof text === 'number') ? true : false; },
            num: function(parameter) { return typeof parameter === 'number' ? true : false; },
            boo: function(parameter) { return typeof parameter === 'boolean' ? true : false; },
            fun: function(parameter) { return typeof parameter === 'function' ? true : false; },
            obj: function(parameter) {
                var hasObj;
                for (var o in parameter) {
                    hasObj = true;
                    break;
                }
                return (typeof parameter === 'object' && hasObj) ? true : false;
            },


            //查找dom对象的class值
            hasClass: function(dom, cls) {
                cls = cls || '';
                if (cls.replace(/\s/g, '').length === 0) {
                    return false;
                }
                return new RegExp(' ' + cls + ' ').test(' ' + dom.className + ' ');
            },

            //增加doc对象的class值
            addClass: function(dom, cls) {
                if (!common.hasClass(dom, cls)) {
                    dom.className = dom.className === '' ? cls : dom.className + ' ' + cls;
                }
            },

            //删除doc对象的class值
            removeClass: function(dom, cls) {
                if (common.hasClass(dom, cls)) {
                    var newClass = ' ' + dom.className.replace(/[\t\r\n]/g, '') + ' ';
                    while (newClass.indexOf(' ' + cls + ' ') >= 0) {
                        newClass = newClass.replace(' ' + cls + ' ', ' ');
                    }
                    dom.className = newClass.replace(/^\s+|\s+$/g, '');
                }
            },

            //获取当前页面可视范围的宽高
            //获取iframe最顶层可视范围的宽高
            docSize: function() {
                var docWidth = native.doc(false).documentElement.clientWidth,
                    docHeight = native.doc(false).documentElement.clientHeight,
                    topWidth = native.doc(true).documentElement.clientWidth,
                    topHeight = native.doc(true).documentElement.clientHeight;

                return {
                    'docWidth': docWidth,
                    'docHeight': docHeight,
                    'topWidth': topWidth,
                    'topHeight': topHeight
                };
            },

            //改变层级关系
            //一般当事件发生在对象弹窗时
            //对象弹窗层级递增，进入最顶层
            zIndex: function(dom) {
                field.zIndex++;
                dom.style.zIndex = field.zIndex;
            },

            //弹窗统一显示动画
            showAnimation: function(dom, mask, shade) {

                setTimeout(function() {

                    if (shade) {
                        mask.style.opacity = '1';
                        mask.style.zIndex = field.zIndex;

                        mask.setAttribute('shade', field.zIndex);
                        dom.setAttribute('shade', field.zIndex);
                    }

                    //初始化增加层级关系
                    //无论之前是否存在弹窗，都使弹窗置于最顶端
                    common.zIndex(dom);

                    //增加透明度，显示动画
                    dom.style.opacity = '1';

                    //增加动画class
                    common.addClass(dom, 'Lkx-Popup-show');
                });
            },

            //弹窗统一关闭动画
            //所有弹窗的关闭均进入此方法
            closeAnimation: function(dom, topPage, shade, type) {

                var shadeMatching,
                    mask = native.query('.Lkx-Popup-shade', topPage),
                    remind = native.query('.Lkx-Popup-remind-bulk', topPage);

                //针对remind执行之前存在销毁处理
                if (remind && type === 3) {
                    dom = remind;
                    clearTimeout(field.remindTimer);
                } else if (type === 3) {
                    return false;
                }

                //针对loading、remind以及tips进行单独处理
                //不进行偏移量减除
                if (type !== 2 && type !== 3 && type !== 4) {
                    field.movesNum = field.movesNum - 40;
                }

                //针对背景遮罩层进行销毁处理
                if (shade && mask) {
                    shadeMatching = parseInt(dom.getAttribute('shade')) === parseInt(mask.getAttribute('shade'));
                    if (shadeMatching) {
                        mask.style.opacity = '0';
                    }
                }

                //针对滚动条隐藏进行释放
                if (common.hasClass(native.query('body', topPage), 'Lkx-noScrollBar')) {
                    common.removeClass(native.query('body', topPage), 'Lkx-noScrollBar');
                }

                //修改透明度
                //增加动画class
                dom.style.opacity = '0';
                common.addClass(dom, 'Lkx-Popup-hide');

                setTimeout(function() {
                    if (shade && shadeMatching) {
                        native.query('body', topPage).removeChild(mask);
                    }
                    native.query('body', topPage).removeChild(dom);
                }, 150);
            }
        };

    //弹窗生成构造函数
    //对所属弹窗的标签创建
    //样式赋值以及事件增加
    var Skeleton = function(parameter1, parameter2, parameter3, parameter4) {

        this.type = parameter1;

        switch (this.type) {
            case 0:
                this.text = parameter2;
                this.parameter = parameter3;

                break;
            case 1:

                this.parameter = parameter2;
                this.text = this.parameter.text;
                this.parBtn = (common.obj(this.parameter.btn) && this.parameter.btn.length === 2) ? this.parameter.btn : ['空', '空'];
                this.parBtn1 = parameter3;
                this.parBtn2 = parameter4;

                break;
            case 2:

                this.parameter = parameter2;
                this.text = this.parameter.text;

                break;
            case 3:

                this.text = parameter2;
                this.time = parameter3;
                this.parameter = parameter4;

                break;
            case 4:

                this.text = parameter2;
                this.dom = parameter3;

                this.parameter = parameter4;
                this.time = this.parameter.time;

                break;
            case 5:

                this.parameter = parameter2;
                this.size = this.parameter.size;
                this.src = this.parameter.src;
                this.shrinkCall = this.parameter.shrinkCall;
                this.label = this.parameter.label;
                break;
        }

        this.shade = this.parameter.shade;
        this.headerText = this.parameter.title;
        this.style = this.parameter.style;
        this.topPage = this.parameter.topPage;
        this.offset = this.parameter.offset;
        this.closeCall = this.parameter.closeCall;
        this.scrollBar = this.parameter.scrollBar;
        this.diy = this.parameter.diy;

        //是否禁用滚动条
        if (this.scrollBar) { common.addClass(native.query('body', this.topPage), 'Lkx-noScrollBar'); }

        this.materials();
        this.assemble();
        this.className();
        this.copy();
        this.event();
    };

    Skeleton.prototype = {

        //创建所有类型弹窗的标签
        //根据不同的弹窗类型进行组装
        materials: function() {

            this.bulk = native.create('div');
            this.animation = native.create('div');
            this.title = native.create('div');
            this.titleText = native.create('p');
            this.titleClose = native.create('div');
            this.content = native.create('div');
            this.contentText = native.create('p');
            this.btn = native.create('div');
            this.btn1 = native.create('div');
            this.btn2 = native.create('div');

            //隐藏域移动板
            this.move = native.create('div');

            //背景遮罩层
            this.mask = native.create('div');
        },

        //根据弹窗类型进行标签初始化组装
        assemble: function() {

            var that = this;

            switch (that.type) {
                case 0:

                    that.title.appendChild(that.titleText);
                    that.title.appendChild(that.titleClose);
                    that.content.appendChild(that.contentText);
                    that.bulk.appendChild(that.title);
                    that.bulk.appendChild(that.content);

                    break;
                case 1:

                    that.title.appendChild(that.titleText);
                    that.title.appendChild(that.titleClose);
                    that.content.appendChild(that.contentText);
                    that.btn.appendChild(that.btn1);
                    that.btn.appendChild(that.btn2);
                    that.bulk.appendChild(that.title);
                    that.bulk.appendChild(that.content);
                    that.bulk.appendChild(that.btn);

                    break;
                case 2:

                    var loadingStyle = {
                        0: function() {
                            for (var i = 0; i < 5; i++) {
                                that.bulk.appendChild(native.create('div'));
                            }
                        },
                        1: function() {
                            for (var i = 0; i < 3; i++) {
                                that.bulk.appendChild(native.create('div'));
                            }
                        },
                        2: function() {
                            for (var i = 0; i < 8; i++) {
                                that.bulk.appendChild(native.create('div'));
                            }
                        }
                    };

                    loadingStyle[that.style]();

                    //是否存在文案判断
                    if (common.str(that.text)) { that.bulk.appendChild(that.contentText); }

                    break;
                case 3:

                    that.bulk.appendChild(that.contentText);

                    break;
                case 4:

                    //释放已绑定的空间
                    that.bulk = [];
                    that.arrow = [];
                    that.content = [];
                    that.contentText = [];

                    for (var d = 0; d < that.dom.length; d++) {

                        that.bulk[d] = native.create('div');
                        that.content[d] = native.create('div');
                        that.contentText[d] = native.create('p');

                        //特殊三角箭头
                        that.arrow[d] = native.create('span');

                        that.content[d].appendChild(that.contentText[d]);
                        that.bulk[d].appendChild(that.arrow[d]);
                        that.bulk[d].appendChild(that.content[d]);

                        that.into(that.bulk[d]);
                    }

                    return;
                case 5:

                    //头部缩放按钮
                    that.titleShrink = native.create('div');

                    //右下角调整大小按钮
                    that.resize = native.create('div');

                    if (common.obj(that.label)) {

                        try {
                            that.content.appendChild(that.label);
                        } catch (err) {
                            that.content.appendChild(that.label.get(0));
                        }

                    } else {

                        //特殊iframe层
                        that.iframe = native.create('iframe');
                        that.content.appendChild(that.iframe);
                    }

                    that.title.appendChild(that.titleText);
                    that.title.appendChild(that.titleShrink);
                    that.title.appendChild(that.titleClose);
                    that.content.appendChild(that.resize);
                    that.bulk.appendChild(that.title);
                    that.bulk.appendChild(that.content);
                    break;
            }

            that.into(that.bulk);
        },

        //如果存在层级嵌套，根据topPage参数来将弹窗放入对应的页面中
        //此方法是将弹窗置于页面中
        //包括mask方法
        into: function(dom) {

            native.query('body', this.topPage).appendChild(dom);

            if (!native.query('.Lkx-Popup-mover', this.topPage)) { native.query('body', this.topPage).appendChild(this.move); }
            if (!native.query('.Lkx-Popup-shade', this.topPage) && this.shade) { native.query('body', this.topPage).appendChild(this.mask); }
        },

        //增加样式class值
        //所有弹窗样式入口
        className: function() {

            //公共移动板
            common.addClass(this.move, 'Lkx-Popup-mover');

            //遮罩层
            common.addClass(this.mask, 'Lkx-Popup-shade');

            //统一增加关闭按钮
            common.addClass(this.titleClose, 'Lkx-icon');
            common.addClass(this.titleClose, 'Lkx-icon-close');

            switch (this.type) {
                case 0:

                    common.addClass(this.bulk, 'Lkx-Popup-alert-bulk');
                    common.addClass(this.title, 'Lkx-Popup-alert-title');
                    common.addClass(this.titleClose, 'Lkx-Popup-close');
                    common.addClass(this.content, 'Lkx-Popup-alert-content');

                    this.styleStatus(this.bulk, 'alert');

                    break;
                case 1:

                    common.addClass(this.bulk, 'Lkx-Popup-ask-bulk');
                    common.addClass(this.title, 'Lkx-Popup-ask-title');
                    common.addClass(this.titleClose, 'Lkx-Popup-close');
                    common.addClass(this.content, 'Lkx-Popup-ask-content');
                    common.addClass(this.btn, 'Lkx-Popup-ask-btn');

                    common.addClass(this.btn, Lkx.info().device === 'pc' ? 'Lkx-Popup-ask-btn-pc' : 'Lkx-Popup-ask-btn-mobile');

                    this.styleStatus(this.bulk, 'ask');

                    break;
                case 2:

                    common.addClass(this.bulk, this.shade === true ? 'Lkx-Popup-loading-bulk' : 'Lkx-Popup-loading-bulk-noShade');

                    //增加风格样式专属class值
                    switch (this.style) {
                        case 0:
                            common.addClass(this.bulk, 'Lkx-Popup-loading-bulk-0');
                            break;
                        case 1:
                            common.addClass(this.bulk, 'Lkx-Popup-loading-bulk-1');
                            break;
                        case 2:
                            common.addClass(this.bulk, 'Lkx-Popup-loading-bulk-2');

                            //是否存在文案判断
                            if (common.str(this.text)) { common.addClass(this.contentText, 'Lkx-Popup-loading-text-special'); }

                            break;
                    }

                    //是否存在文案判断
                    if (common.str(this.text)) { common.addClass(this.contentText, this.shade === true ? 'Lkx-Popup-loading-text' : 'Lkx-Popup-loading-text-noShade'); }

                    break;
                case 3:

                    //对之前存在的弹窗进行销毁
                    common.closeAnimation(this.bulk, this.topPage, this.shade, this.type);
                    common.addClass(this.bulk, 'Lkx-Popup-remind-bulk');

                    this.styleStatus(this.bulk, 'remind');

                    break;
                case 4:

                    for (var d = 0; d < this.dom.length; d++) {
                        common.addClass(this.bulk[d], 'Lkx-Popup-tips-bulk');
                        common.addClass(this.arrow[d], 'Lkx-Popup-tips-arrow');
                        common.addClass(this.content[d], 'Lkx-Popup-tips-content');

                        this.styleStatus(this.bulk[d], 'tips');

                        common.showAnimation(this.bulk[d], this.mask, this.shade);
                    }

                    return false;
                case 5:

                    common.addClass(this.bulk, 'Lkx-Popup-open-bulk');
                    common.addClass(this.title, 'Lkx-Popup-open-title');

                    common.addClass(this.titleShrink, 'Lkx-icon');
                    common.addClass(this.titleShrink, 'Lkx-icon-max');
                    common.addClass(this.titleShrink, 'Lkx-Popup-shrink');

                    common.addClass(this.titleClose, 'Lkx-Popup-close');

                    common.addClass(this.content, 'Lkx-Popup-open-content');
                    common.addClass(this.resize, 'Lkx-Popup-open-resize');

                    this.styleStatus(this.bulk, 'open');

                    break;
            }

            //缩放状态
            this.bulk.setAttribute('shrinkState', '0');

            //this.bulk 弹窗外框架
            //this.mask 背景遮罩层
            //this.shade 是否显示背景遮罩层依据
            common.showAnimation(this.bulk, this.mask, this.shade);
        },

        //某些特定弹窗需要的样式风格
        //包括官方提供的几种状态风格或diy进入
        //进行判断，对应指定的风格class值
        styleStatus: function(dom, type) {

            var that = this,
                headerText;

            if (common.boo(that.diy.color) && common.boo(that.diy.background)) {

                switch (that.style) {
                    case 'default':
                        headerText = '提示';

                        break;
                    case 'primary':

                        headerText = '提示';
                        common.addClass(dom, 'Lkx-Popup-' + type + '-bulk-primary');

                        break;
                    case 'success':

                        headerText = '成功';
                        common.addClass(dom, 'Lkx-Popup-' + type + '-bulk-success');

                        break;
                    case 'info':

                        headerText = '信息';
                        common.addClass(dom, 'Lkx-Popup-' + type + '-bulk-info');

                        break;
                    case 'warning':

                        headerText = '警告';
                        common.addClass(dom, 'Lkx-Popup-' + type + '-bulk-warning');

                        break;
                    case 'danger':

                        headerText = '错误';
                        common.addClass(dom, 'Lkx-Popup-' + type + '-bulk-danger');
                        break;
                }
            } else {

                if (type === 'tips') {

                    setTimeout(function() {
                        if (common.hasClass(dom, 'Lkx-Popup-tips-bulk-right')) {
                            dom.childNodes[0].style.borderLeft = '8px solid ' + that.diy.background;
                        } else {
                            dom.childNodes[0].style.borderRight = '8px solid ' + that.diy.background;
                        }

                        dom.childNodes[1].style.backgroundColor = that.diy.background;
                        dom.childNodes[1].childNodes[0].style.color = that.diy.color;
                    }, 10);

                } else {

                    headerText = '提示';

                    dom.style.border = '1px solid ' + that.diy.background;
                    if (type === 'remind') {
                        that.contentText.style.color = that.diy.color;
                        dom.style.background = that.diy.background;
                    }
                    if (that.titleText) { that.titleText.style.cssText = 'color:' + that.diy.color + ';background:' + that.diy.background; }
                    if (that.titleClose) { that.titleClose.style.cssText = 'color:' + that.diy.color + ';background:' + that.diy.background; }
                    if (that.titleShrink) { that.titleShrink.style.cssText = 'color:' + that.diy.color + ';background:' + that.diy.background; }

                    common.addClass(dom, 'Lkx-Popup-diy');
                }
            }

            if (!common.str(that.headerText)) { that.headerText = headerText; }
        },

        //将文案进行拼装
        //确定最后的宽高
        copy: function() {

            switch (this.type) {
                case 0:
                    this.titleText.innerHTML = this.headerText;
                    this.contentText.innerHTML = this.text;

                    break;
                case 1:

                    this.titleText.innerHTML = this.headerText;
                    this.contentText.innerHTML = this.text;
                    this.btn1.innerHTML = this.parBtn[0];
                    this.btn2.innerHTML = this.parBtn[1];

                    break;
                case 2:

                    //是否存在文案判断
                    if (common.str(this.text)) { this.contentText.innerHTML = this.text; }

                    break;
                case 3:

                    this.contentText.innerHTML = this.text;

                    break;
                case 4:

                    for (var d = 0; d < this.dom.length; d++) {
                        this.contentText[d].innerHTML = this.text;

                        //对页面中每个单独的dom对象进行尺寸改变
                        this.eSize(this.bulk[d], this.topPage, this.dom[d]);
                    }

                    return false;
                case 5:

                    this.titleText.innerHTML = this.headerText;

                    if (!common.obj(this.label)) {
                        this.iframe.src = this.src;
                        this.iframe.setAttribute('frameborder', '0');
                    }

                    this.bulk.style.width = this.size[0];
                    this.bulk.style.height = this.size[1];

                    break;
            }

            //调整弹窗偏移量
            this.eSize(this.bulk, this.topPage);
        },

        //让弹窗处于居中状态
        //增加偏移量，使其横向居中且纵向偏上
        eSize: function(dom, topPage, node) {

            //tips层单独创建
            if (this.type === 4) {
                dom.style.top = node.offsetTop + 'px';

                if (node.offsetWidth + node.offsetLeft + dom.offsetWidth + 30 > common.docSize().docWidth) {
                    dom.style.left = (node.offsetLeft - dom.offsetWidth) + 'px';

                    common.addClass(dom, 'Lkx-Popup-tips-bulk-right');
                    common.addClass(dom.childNodes[0], 'Lkx-Popup-tips-arrow-right');

                } else {
                    dom.style.left = (node.offsetWidth + node.offsetLeft) + 'px';
                }
            } else {

                //循环查找offset是否符合规范
                //若是输入的不符合规范，将默认指定为center位置
                for (var o = 0; o < field.offset.length; o++) {
                    if (this.offset === field.offset[o]) {
                        this.offset = this.offset;
                        break;
                    } else {
                        if (o === field.offset.length - 1) {
                            this.offset = 'center';
                        }
                    }
                }

                if (((this.topPage ? common.docSize().topHeight : common.docSize().docHeight) / 2) - dom.offsetHeight / 2 <= 0) {
                    dom.style.top = 0;
                    dom.style.height = (this.topPage ? common.docSize().topHeight : common.docSize().docHeight) + 'px';
                    this.content.style.maxHeight = ((this.topPage ? common.docSize().topHeight : common.docSize().docHeight) - 40) + 'px';
                    this.content.style.display = 'block';
                } else {
                    if (this.offset === 'top') {
                        dom.style.top = '0px';
                    } else if (this.offset === 'center' || this.offset === 'left' | this.offset === 'right') {
                        dom.style.top = (((this.topPage ? common.docSize().topHeight : common.docSize().docHeight) / 2) - dom.offsetHeight / 2) + (Lkx.info().device === 'mobile' || this.type === 2 || this.type === 3 ? 0 : field.movesNum) + 'px';
                    } else if (this.offset === 'bottom') {
                        dom.style.top = ((this.topPage ? common.docSize().topHeight : common.docSize().docHeight)) - (dom.offsetHeight + (this.type === 3 ? 50 : 0)) + 'px';
                    }
                }

                if (this.offset === 'left') {
                    dom.style.left = '0px';
                } else if (this.offset === 'center' || this.offset === 'top' || this.offset === 'bottom') {
                    dom.style.left = ((this.topPage ? common.docSize().topWidth : common.docSize().docWidth) / 2) - (dom.offsetWidth / 2) + (Lkx.info().device === 'mobile' || this.type === 2 || this.type === 3 ? 0 : field.movesNum) + 'px';
                } else if (this.offset === 'right') {
                    dom.style.left = ((this.topPage ? common.docSize().topWidth : common.docSize().docWidth)) - dom.offsetWidth + 'px';
                }

                if (this.type !== 2 && this.type !== 3) {
                    field.movesNum = field.movesNum + 40;
                }
            }
        },

        //增加关闭事件
        //增加ask层的按钮事件
        event: function() {

            var that = this;

            switch (that.type) {
                case 0:

                    that.titleClose.onclick = function() {

                        //执行关闭按钮回调
                        that.closeCall();

                        //that.bulk 弹窗外框架
                        //that.topPage 弹出位置的层级
                        //that.shade 是否显示背景遮罩层依据
                        common.closeAnimation(that.bulk, that.topPage, that.shade);
                    };

                    //更改层级关系
                    that.content.onclick = function() { common.zIndex(that.bulk); };

                    //当处于pc端时，开始调用Drag方法
                    //当弹窗可以进行拖动
                    if (Lkx.info().device === 'pc') { that.frameOper(); }

                    break;
                case 1:

                    that.titleClose.onclick = function() {

                        //执行关闭按钮回调
                        that.closeCall();

                        //that.bulk 弹窗外框架
                        //that.topPage 弹出位置的层级
                        //that.shade 是否显示背景遮罩层依据
                        common.closeAnimation(that.bulk, that.topPage, that.shade);
                    };

                    //更改层级关系
                    that.content.onclick = function() { common.zIndex(that.bulk); };

                    //再次更改层级关系
                    //阻止冒泡，禁止传递事件至下层
                    that.btn.onclick = function(event) {
                        event.stopPropagation();
                        common.zIndex(that.bulk);
                    };

                    that.btn1.onclick = that.parBtn1;
                    that.btn2.onclick = that.parBtn2;

                    //当处于pc端时，开始调用Drag方法
                    //当弹窗可以进行拖动
                    if (Lkx.info().device === 'pc') { that.frameOper(); }

                    break;
                case 3:

                    field.remindTimer = setTimeout(function() {

                        //that.bulk 弹窗外框架
                        //that.topPage 弹出位置的层级
                        //that.shade 是否显示背景遮罩层依据
                        common.closeAnimation(that.bulk, that.topPage, that.shade, 3);

                    }, that.time);

                    break;
                case 4:

                    field.tipsTimer = setTimeout(function() {
                        for (var d = 0; d < that.dom.length; d++) {
                            common.closeAnimation(that.bulk[d], that.topPage, that.shade, 4);
                        }
                    }, that.time);

                    break;
                case 5:

                    that.titleShrink.onclick = function() {

                        var shrinkState = that.bulk.getAttribute('shrinkState');

                        if (shrinkState === '0') {
                            common.addClass(that.bulk, 'Lkx-Popup-animation');
                            common.addClass(that.bulk, 'Lkx-Popup-max');

                            //更改缩放图标
                            common.removeClass(that.titleShrink, 'Lkx-icon-max');
                            common.addClass(that.titleShrink, 'Lkx-icon-min');

                            that.bulk.setAttribute('shrinkState', '1');

                            //执行缩放回调
                            that.shrinkCall('max');

                        } else if (shrinkState === '1') {
                            common.addClass(that.bulk, 'Lkx-Popup-animation');
                            common.removeClass(that.bulk, 'Lkx-Popup-max');

                            //更改缩放图标
                            common.removeClass(that.titleShrink, 'Lkx-icon-min');
                            common.addClass(that.titleShrink, 'Lkx-icon-max');

                            that.bulk.setAttribute('shrinkState', '0');

                            //执行缩放回调
                            that.shrinkCall('min');
                        }
                    };

                    that.titleClose.onclick = function() {

                        //执行关闭按钮回调
                        that.closeCall();

                        //that.bulk 弹窗外框架
                        //that.topPage 弹出位置的层级
                        //that.shade 是否显示背景遮罩层依据
                        common.closeAnimation(that.bulk, that.topPage, that.shade);
                    };

                    //当处于pc端时，开始调用Drag方法
                    //当弹窗可以进行拖动
                    if (Lkx.info().device === 'pc') { that.frameOper(true); }

                    break;
            }
        },

        //帧的操作
        //操作弹窗滑动事件
        //增加弹窗可缩放大小事件
        frameOper: function(changeSize) {

            var that = this,
                frameOperThis;

            that.saveX = that.bulk.offsetLeft;
            that.saveY = that.bulk.offsetTop;
            that.saveWidth = that.bulk.offsetWidth;
            that.saveHeight = that.bulk.offsetHeight;

            that.titleText.addEventListener('mousedown', dowm);

            //判断是否存在changeSize
            //存在将对窗口进行拖拽缩放大小
            if (changeSize) { that.resize.addEventListener('mousedown', dowm); }

            function dowm(event) {

                that.event = event || win.event;

                //记录事件所发生的对象
                //用于识别是改变大小还是拖拽位置
                frameOperThis = common.hasClass(this, 'Lkx-Popup-open-resize');

                //更改层级关系
                common.zIndex(that.bulk);

                that.move.style.display = 'block';

                //删除显示动画class
                common.removeClass(that.bulk, 'Lkx-Popup-show');
                common.removeClass(that.bulk, 'Lkx-Popup-animation');

                that.dowmX = that.event.clientX;
                that.dowmY = that.event.clientY;

                native.doc(that.topPage).addEventListener('mousemove', move);
                native.doc(that.topPage).addEventListener('mouseup', up);

                native.query('.Lkx-Popup-mover', that.topPage).style.display = 'block';
            }

            function move(event) {

                that.event = event || win.event;

                //缩放弹窗的大小
                if (frameOperThis) {

                    that.moveWidth = that.saveWidth + (that.event.clientX - that.dowmX);
                    that.moveHeight = that.saveHeight + (that.event.clientY - that.dowmY);

                    if (that.moveWidth <= 260) { that.moveWidth = 260; }
                    if (that.moveHeight <= 140) { that.moveHeight = 140; }

                    that.bulk.style.width = that.moveWidth + 'px';
                    that.bulk.style.height = that.moveHeight + 'px';
                }

                //改变弹窗的位置
                else {

                    that.moveX = that.event.clientX - that.dowmX + that.saveX;
                    that.moveY = that.event.clientY - that.dowmY + that.saveY;

                    //限制共同的拖拽范围
                    //left点以及top点都以0为限制点
                    if (that.moveX <= 0) { that.moveX = 0; }
                    if (that.moveY <= 0) { that.moveY = 0; }

                    //限制可拖动的范围
                    //分别适配了置于最顶部iframe以及当前层级
                    if (that.moveX >= (that.topPage ? common.docSize().topWidth : common.docSize().docWidth) - that.bulk.offsetWidth) {
                        that.moveX = (that.topPage ? common.docSize().topWidth : common.docSize().docWidth) - that.bulk.offsetWidth;
                    }
                    if (that.moveY >= (that.topPage ? common.docSize().topHeight : common.docSize().docHeight) - that.bulk.offsetHeight) {
                        that.moveY = (that.topPage ? common.docSize().topHeight : common.docSize().docHeight) - that.bulk.offsetHeight;
                    }

                    that.bulk.style.left = that.moveX + 'px';
                    that.bulk.style.top = that.moveY + 'px';
                }
            }

            function up() {

                that.saveX = that.bulk.offsetLeft;
                that.saveY = that.bulk.offsetTop;
                that.saveWidth = that.bulk.offsetWidth;
                that.saveHeight = that.bulk.offsetHeight;

                native.doc(that.topPage).removeEventListener('mousemove', move, false);
                native.doc(that.topPage).removeEventListener('mouseup', up, false);

                native.query('.Lkx-Popup-mover', that.topPage).style.display = 'none';
            }
        }
    };

    //向外暴露的Popup构造函数
    //通过此方法进行展开弹窗
    var Popup = function() {
        this.name = 'Lkx-Popup';
        this.info = Lkx.info().version;
    };

    Popup.fn = Popup.prototype;

    //提示层弹窗
    //类似原生alert的弹窗
    //需要用户点击右上角关闭按钮进行关闭
    Popup.fn.alert = function(text, parameter) {

        this.parameter = common.obj(parameter) ? parameter : {};
        this.diy = common.obj(this.parameter.diy) ? this.parameter.diy : {};

        return new Skeleton(0, common.str(text) ? text : '无内容', {
            title: this.parameter.title,
            style: common.str(this.parameter.style) ? this.parameter.style : 'default',
            topPage: common.boo(this.parameter.topPage) ? this.parameter.topPage : false,
            shade: common.boo(this.parameter.shade) ? this.parameter.shade : false,
            offset: common.str(this.parameter.offset) ? this.parameter.offset : 'center',
            closeCall: common.fun(this.parameter.closeCall) ? this.parameter.closeCall : function() {},
            scrollBar: common.boo(this.parameter.scrollBar) ? this.parameter.scrollBar : false,
            diy: {
                color: common.str(this.diy.color) ? this.diy.color : false,
                background: common.str(this.diy.background) ? this.diy.background : false,
            }
        });
    };

    //询问层弹窗
    //在页面中部弹出带有两个按钮的提示信息
    //需要用户进行交互处理
    Popup.fn.ask = function(parameter, btn1, btn2) {

        this.parameter = common.obj(parameter) ? parameter : {};
        this.diy = common.obj(this.parameter.diy) ? this.parameter.diy : {};

        return new Skeleton(1, {
            text: common.str(this.parameter.text) ? this.parameter.text : '无内容',
            title: this.parameter.title,
            style: common.str(this.parameter.style) ? this.parameter.style : 'default',
            topPage: common.boo(this.parameter.topPage) ? this.parameter.topPage : false,
            shade: common.boo(this.parameter.shade) ? this.parameter.shade : false,
            btn: this.parameter.btn,
            offset: common.str(this.parameter.offset) ? this.parameter.offset : 'center',
            closeCall: common.fun(this.parameter.closeCall) ? this.parameter.closeCall : function() {},
            scrollBar: common.boo(this.parameter.scrollBar) ? this.parameter.scrollBar : false,
            diy: {
                color: common.str(this.diy.color) ? this.diy.color : false,
                background: common.str(this.diy.background) ? this.diy.background : false,
            },
        }, common.fun(btn1) ? btn1 : {}, common.fun(btn2) ? btn2 : {});
    };

    //等待层弹窗
    //为跳转而生，中间的过渡动画
    Popup.fn.loading = function(parameter) {

        this.parameter = common.obj(parameter) ? parameter : {};
        this.style = common.num(this.parameter.style) ? this.parameter.style <= 2 && this.parameter.style >= 0 ? this.parameter.style : 0 : common.str(this.parameter.style) ? parseInt(this.parameter.style) <= 2 && parseInt(this.parameter.style) >= 0 ? parseInt(this.parameter.style) : 0 : 0;
        this.diy = common.obj(this.parameter.diy) ? this.parameter.diy : {};

        return new Skeleton(2, {
            style: this.style,
            topPage: common.boo(this.parameter.topPage) ? this.parameter.topPage : false,
            shade: common.boo(this.parameter.shade) ? this.parameter.shade : false,
            offset: common.str(this.parameter.offset) ? this.parameter.offset : 'center',
            scrollBar: common.boo(this.parameter.scrollBar) ? this.parameter.scrollBar : false,
            text: common.str(this.parameter.text) ? this.parameter.text : ''
        });
    };

    //提醒层弹窗
    //处理一些时间较短的提示信息
    Popup.fn.remind = function(text, time, parameter) {

        this.parameter = common.obj(parameter) ? parameter : common.obj(time) ? time : {};
        this.time = common.num(time) ? time : common.str(time) ? parseInt(time) : 3000;
        this.diy = common.obj(this.parameter.diy) ? this.parameter.diy : {};

        return new Skeleton(3, common.str(text) ? text : '无内容', this.time, {
            style: common.str(this.parameter.style) ? this.parameter.style : 'default',
            topPage: common.boo(this.parameter.topPage) ? this.parameter.topPage : false,
            shade: common.boo(this.parameter.shade) ? this.parameter.shade : false,
            offset: common.str(this.parameter.offset) ? this.parameter.offset : 'center',
            scrollBar: common.boo(this.parameter.scrollBar) ? this.parameter.scrollBar : false,
            diy: {
                color: common.str(this.diy.color) ? this.diy.color : false,
                background: common.str(this.diy.background) ? this.diy.background : false,
            }
        });
    };

    //小贴士弹窗
    //吸附在对象右侧或者左侧的小提示框
    Popup.fn.tips = function(text, dom, parameter) {

        this.parameter = common.obj(parameter) ? parameter : {};
        this.time = common.num(this.parameter.time) ? this.parameter.time : common.str(this.parameter.time) ? parseInt(this.parameter.time) : 3000;
        this.diy = common.obj(this.parameter.diy) ? this.parameter.diy : {};

        //判断吸附对象
        if (common.str(dom)) {
            this.dom = native.queryAll(dom);
        } else if (common.num(dom.length)) {
            this.dom = dom;
        } else {
            this.dom = {
                0: dom,
                length: '1'
            };
        }

        return new Skeleton(4, common.str(text) ? text : '无内容', this.dom, {
            time: this.time,
            style: common.str(this.parameter.style) ? this.parameter.style : 'default',
            scrollBar: common.boo(this.parameter.scrollBar) ? this.parameter.scrollBar : false,
            shade: common.boo(this.parameter.shade) ? this.parameter.shade : false,
            diy: {
                color: common.str(this.diy.color) ? this.diy.color : false,
                background: common.str(this.diy.background) ? this.diy.background : false,
            }
        });
    };

    //窗口层弹窗
    //当前页面弹出带有iframe标签的弹出层
    Popup.fn.open = function(parameter) {

        this.parameter = common.obj(parameter) ? parameter : {};
        this.diy = common.obj(this.parameter.diy) ? this.parameter.diy : {};

        return new Skeleton(5, {
            title: this.parameter.title,
            label: this.parameter.content,
            style: common.str(this.parameter.style) ? this.parameter.style : 'default',
            topPage: common.boo(this.parameter.topPage) ? this.parameter.topPage : false,
            shade: common.boo(this.parameter.shade) ? this.parameter.shade : false,
            size: common.obj(this.parameter.size) ? this.parameter.size : Lkx.info().device === 'mobile' ? ['100%', '100%'] : ['900px', '600px'],
            src: common.str(this.parameter.src) ? this.parameter.src : '',
            closeCall: common.fun(this.parameter.closeCall) ? this.parameter.closeCall : function() {},
            shrinkCall: common.fun(this.parameter.shrinkCall) ? this.parameter.shrinkCall : function() {},
            offset: common.str(this.parameter.offset) ? this.parameter.offset : 'center',
            scrollBar: common.boo(this.parameter.scrollBar) ? this.parameter.scrollBar : false,
            diy: {
                color: common.str(this.diy.color) ? this.diy.color : false,
                background: common.str(this.diy.background) ? this.diy.background : false,
            }
        });
    };

    //关闭单一类型弹窗层
    //获取传入的parameter值
    //通过this.closeAll来达到关闭目的
    Popup.fn.close = function(parameter) {

        if (common.str(parameter)) {
            var cls;
            switch (parameter) {
                case 'alert':
                    cls = ['Lkx-Popup-alert-bulk'];
                    break;
                case 'ask':
                    cls = ['Lkx-Popup-ask-bulk'];
                    break;
                case 'loading':
                    cls = ['Lkx-Popup-loading-bulk', 'Lkx-Popup-loading-bulk-noShade'];
                    break;
                case 'remind':
                    cls = ['Lkx-Popup-remind-bulk'];
                    break;
                case 'tips':
                    cls = ['Lkx-Popup-tips-bulk'];
                    break;
                case 'open':
                    cls = ['Lkx-Popup-open-bulk'];
                    break;
            }

            return this.closeAll(cls, true);
        }
    };

    //关闭所有弹窗层
    //手动关闭弹窗的方法总入口
    Popup.fn.closeAll = function(cls, separate) {

        var that = this;

        if (common.obj(cls) && separate) {
            that.cla = cls;
        } else {
            that.cla = ['Lkx-Popup-alert-bulk', 'Lkx-Popup-ask-bulk', 'Lkx-Popup-loading-bulk', 'Lkx-Popup-loading-bulk-noShade', 'Lkx-Popup-remind-bulk', 'Lkx-Popup-tips-bulk', 'Lkx-Popup-open-bulk'];
        }

        //进行逐一关闭
        //循环页面存在的所有弹窗
        for (var c = 0; c < that.cla.length; c++) {
            var domTrue = native.queryAll('.' + that.cla[c], true);
            var domFalse = native.queryAll('.' + that.cla[c], false);

            //判断是否存在iframe嵌套
            if (native.doc(true) === native.doc(false)) {
                for (var ef = 0; ef < domFalse.length; ef++) {
                    common.closeAnimation(domFalse[ef], false, true, domFalse[ef].className.indexOf('loading') >= 0 ? 2 : domFalse[ef].className.indexOf('remind') >= 0 ? 3 : null);
                }
            } else {
                for (var eff = 0; eff < domFalse.length; eff++) {
                    common.closeAnimation(domFalse[eff], false, true, domFalse[eff].className.indexOf('loading') >= 0 ? 2 : domFalse[eff].className.indexOf('remind') >= 0 ? 3 : null);
                }

                for (var et = 0; et < domTrue.length; et++) {
                    common.closeAnimation(domTrue[et], true, true, domTrue[et].className.indexOf('loading') >= 0 ? 2 : domTrue[et].className.indexOf('remind') >= 0 ? 3 : null);
                }
            }
        }

        //再次创建弹窗时，让弹窗从0开始生成
        //只适用于使用closeAll时进入
        if (!common.obj(cls) && !separate) {
            field.movesNum = 0;
        }
    };

    win.Popup = new Popup();

})(window);